﻿Public Class clsInhPaczkiWysylki
    Inherits clsPaczkiWysylki

#Region "Attributes"

    Private mvarFirmaKurierska As clsFirmaKurierska
    Private mvarDrutWyslany As Collection(Of clsInhDrutWyslany)
    Private mvarDrutWyslanyDel As Collection(Of clsInhDrutWyslany)

#End Region

#Region "Properties"

    Public Property FirmaKurierska As clsFirmaKurierska
        Get
            Return mvarFirmaKurierska
        End Get
        Set(ByVal value As clsFirmaKurierska)
            mvarFirmaKurierska = value
        End Set
    End Property

    Public Property Drut As Collection(Of clsInhDrutWyslany)
        Get
            Return mvarDrutWyslany
        End Get
        Set(ByVal value As Collection(Of clsInhDrutWyslany))
            mvarDrutWyslany = value
        End Set
    End Property

    Public Property DrutDel As Collection(Of clsInhDrutWyslany)
        Get
            Return mvarDrutWyslanyDel
        End Get
        Set(ByVal value As Collection(Of clsInhDrutWyslany))
            mvarDrutWyslanyDel = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()

        MyBase.New()

        mvarFirmaKurierska = New clsFirmaKurierska
        mvarDrutWyslany = New Collection(Of clsInhDrutWyslany)
        mvarDrutWyslanyDel = New Collection(Of clsInhDrutWyslany)

    End Sub

    Public Sub New(ByVal Id As Integer, ByVal lvarDbHolder As clsDataBase)

        MyBase.New(Id, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarFirmaKurierska = New clsFirmaKurierska(MyBase.FirmaKurierskaId, lvarDbHolder, VAR_ERROR_HANDLER)

        mvarDrutWyslany = New Collection(Of clsInhDrutWyslany)
        mvarDrutWyslanyDel = New Collection(Of clsInhDrutWyslany)

        Dim lvarTabel As DataTable = clsInhDrutWyslany.PobierzWyslanyDrutPaczka(lvarDbHolder, Id)
        Dim lvarI As Integer = 0

        If Not lvarTabel Is Nothing Then
            For Each lvarRow As DataRow In lvarTabel.Rows
                mvarDrutWyslany.Add(New clsInhDrutWyslany(CInt(lvarRow.Item("id")), lvarDbHolder))
                lvarI = lvarI + 1
            Next
        End If

    End Sub

    Public Overloads Sub Save(ByVal lvarDbHolder As clsDataBase)

        MyBase.Save(lvarDbHolder, VAR_ERROR_HANDLER)
        mvarFirmaKurierska = New clsFirmaKurierska(MyBase.FirmaKurierskaId, lvarDbHolder, VAR_ERROR_HANDLER)

        For Each lvarDrutWyslany As clsInhDrutWyslany In mvarDrutWyslanyDel
            lvarDrutWyslany.Delete(lvarDbHolder, VAR_ERROR_HANDLER)
        Next

        For Each lvarDrutWyslany As clsInhDrutWyslany In mvarDrutWyslany
            lvarDrutWyslany.PaczkiWysylkiId = CStr(MyBase.Id)
            lvarDrutWyslany.Save(lvarDbHolder)
        Next

    End Sub

    Public Overloads Sub Delete(ByVal lvarDbHolder As clsDataBase)

        For Each lvarDrutWyslany As clsInhDrutWyslany In mvarDrutWyslanyDel
            lvarDrutWyslany.Delete(lvarDbHolder, VAR_ERROR_HANDLER)
        Next

        For Each lvarDrutWyslany As clsInhDrutWyslany In mvarDrutWyslany
            lvarDrutWyslany.Delete(lvarDbHolder, VAR_ERROR_HANDLER)
        Next
        MyBase.Delete(lvarDbHolder, VAR_ERROR_HANDLER)

    End Sub


#End Region

End Class
